package com.sky.controller.user;

import com.sky.dto.*;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;
    @PostMapping("submit")
    public Result<OrderSubmitVO> add(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        return Result.success(orderService.add(ordersSubmitDTO));
    }
    @PutMapping("/payment")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }
    @GetMapping("/historyOrders")
    public Result<PageResult> search(@RequestParam String page, @RequestParam String pageSize, @RequestParam(required = false) String status){
        return Result.success(orderService.search(page,pageSize,status));
    }
    @GetMapping("/orderDetail/{id}")
    public Result<Orders> getOrderDetail(@PathVariable Long id){
        return Result.success(orderService.getOrderDetail(id));
    }
    @PutMapping("/cancel/{id}")
    public Result<String> cancel(@PathVariable Long id){
        orderService.cancel(id);
        return Result.success();
    }
    @PostMapping("/repetition/{id}")
    public Result<String> repetition(@PathVariable Long id){
        orderService.repetition(id);
        return Result.success();
    }
    @GetMapping("/reminder/{id}")
    public Result<String> reminder(@PathVariable Long id){
        log.info("用户催单");
        orderService.reminder(id);
        return Result.success();
    }
}
